using ApplicationBase.Core;
using ApplicationBase.Core.Web.Extensions;
using Autofac.Extensions.DependencyInjection;
using Autofac;
using WebAppTemplate.CSR.WebAPI;
using Microsoft.EntityFrameworkCore;
using WebAppTemplate.CSR.Repository.DbContexts;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddDefaultControllers();
builder.Services.AddDefaultSwagger();
builder.Services.AddDefaultJWT(builder.Configuration);

builder.Services.AddMemoryCache();

//AutoFac
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
builder.Host.ConfigureContainer<ContainerBuilder>(containerBuilder =>
{
    containerBuilder.RegisterModule<BaseModule>();
    containerBuilder.RegisterModule<AppModule>();
});

//DbContext
builder.Services.AddDbContext<AppDbContext>(options =>
{
    options.UseSqlServer("Server=.;Initial Catalog=Demo;User=sa;Password=Yez123!!;TrustServerCertificate=True;");
});

var app = builder.Build();

if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
